﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ReadFile
{
    class Program
    {
        static void Main(string[] args)
        {
            //byte[] byData = new byte[1000];
            //char[] charData = new char[1000];
            //try
            //{
            //    FileStream aFile = new FileStream("../../Program.cs", FileMode.Open);
            //    aFile.Seek(113, SeekOrigin.Begin);
            //    aFile.Read(byData, 0, 1000);
            //}
            //catch(IOException e)
            //{
            //    Console.WriteLine("An IO exception has been thrown!");
            //    Console.WriteLine(e.ToString());
            //    Console.ReadKey();
            //    return;
            //}
            //Decoder d = Encoding.UTF8.GetDecoder();
            //d.GetChars(byData,0, byData.Length, charData, 0);

            //Console.WriteLine(charData);
            //Console.ReadKey();
            byte[] byData;
            char[] charData;
            try
            {
                FileStream aFile = new FileStream("Temp.txt", FileMode.Create);
                charData = "My pink half of the drainpipe.".ToArray();
                byData = new byte[charData.Length];
                Encoder e = Encoding.UTF8.GetEncoder();
                e.GetBytes(charData, 0, charData.Length, byData, 0, true);
                aFile.Seek(0, SeekOrigin.Begin);
                aFile.Write(byData, 0, byData.Length);


            }
            catch(IOException ex)
            {
                Console.WriteLine("An IO exception has been thrown!");
                Console.WriteLine(ex.ToString());
                Console.ReadKey();
                return;
            }
            
        }
    }
}
